package com.aruio.exception;

import com.arui.Result;
import com.arui.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description 全局异常处理器
 * @Date 2024/8/27 17:41
 * @Created by 10574
 */
@RestControllerAdvice
@Component
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(ServiceException.class)
    public Result<String> handleServiceException(ServiceException se) {
        log.error("ServiceException - Code: {}, Message: {}", se.getCode(), se.getMessage(), se);
        return Result.fail(se.getMessage());
    }
}
